const containerEl = document.getElementById("container");
const txtEl = document.getElementById("txt");
const btnEl = document.getElementById("btn");

btnEl.onclick = function () {
  containerEl.innerHTML = safe`<p>
    ${txtEl.value}
  </p>`;
};

function safe(parts) {
  const values = Array.prototype.slice.apply(arguments).slice(1);
  let str = "";
  for (let i = 0; i < values.length; i++) {
    const v = values[i].replace(/</g, "&lt;").replace(/>/g, "&gt;");
    str += parts[i] + v;
  }

  str += parts[parts.length - 1];
  return str;
}
